myApp_.onPageInit('goods_list', function (page) {
    //请求数据
    GOODS_LIST.request();
});

GOODS_LIST = {};
GOODS_LIST.data = {};
GOODS_LIST.param = {
	search:'',
	community_id:SESSION.get_community_id(),
	seller_id:"",
	goods_category_id:'',
	page:1
};
GOODS_LIST.clean = function () {
	GOODS_LIST.param = {
		search:'',
		community_id:SESSION.get_community_id(),
		seller_id:"",
		goods_category_id:'',
		page:1
	};
}

// 搜索入口
GOODS_LIST.SEARCH__INIT__ = function (kw) {
	GOODS_LIST.clean();
    kw = decodeURI(kw);
    GOODS_LIST.param.search = kw; 
    mainView.router.load({
        url: "src/index/goods/goods_list.html"
    });
}

// 店铺入口
GOODS_LIST.SELLER__INIT__ = function (seller_id) { 
	GOODS_LIST.clean();
    GOODS_LIST.param.seller_id = seller_id;
    mainView.router.load({
        url: "src/index/goods/goods_list.html"
    });
}

// 分类入口
GOODS_LIST.CATEGORY__INIT__ = function (goods_category_id) { 
	GOODS_LIST.clean();
    GOODS_LIST.param.goods_category_id = goods_category_id;
    mainView.router.load({
        url: "src/index/goods/goods_list.html"
    });
}



GOODS_LIST.request = function () {
     request_(
            url_('api/V1/search')
            , GOODS_LIST.param 
            , function (d) {
                if (d.code == 0) {
                    GOODS_LIST.data = d.data;
                    GOODS_LIST.fill_list();
                } else {
                    my_tips_(d.msg);
                }
            }
        );
}

GOODS_LIST.fill_list = function () {
    var goods = GOODS_LIST.data.data; 
    for (var i in  goods) {
        var good = goods[i];
         $.tpl({
	    	url:"src/index/goods/goods_list_fill.html",
	    	context:good,
	    	elem:"#goods_list_container",
	    	append:true 
	    });
    }  
} 